#pragma once

#include "Types.h"
#include <MyControls/Layer.h>

class CXComp;

class Background :
	public My::Layer
{
public:
	Background(CXComp &);
	bool OpenDialog(Extent const & RequiredDim);
	void Close();
	xml::stream & Serialize(xml::stream & s, const String & BasePath);
public:
	virtual bool IsEmpty() const 
		{ return !m_pFootage; }
	bool IsStill() const
		{ return m_pFootage->still(); }
	virtual bool IsSelected() const;
	/// to simplify access to various methods of Footage: size(), dim(), ...
	Footage & operator () () 
		{ return * m_pFootage; } 
	Footage & operator () () const 
		{ return * m_pFootage; } 
	FootageSPtr & GetFootageSPtr() 
		{ return m_pFootage; }
public: /// Placement properies of footage before trimming
	virtual Size GetSourceDuration() const;
	virtual int GetSourceOffset() const 
		{ return m_SourceOffset; }
	virtual void SetSourceOffset(int t); 
	Span GetMaxPossibleTrimming() const ///< only for non-still background
		{ return Span(0, m_pFootage->size()); }
	virtual Span GetTrimming() const 
		{ return m_Trimming; }
	virtual void SetTrimming(Span s); 
	virtual void Select(bool);
public: /// Properies of the non-trimmed part
	bool IsVisible(Size Frame)
		{ return GetSpan().Inside(Frame); }
	/// Returns frame of background footage for the given object frame (-1 indicates that no background frame is available)
	int MyFrame(Size Frame)
		{ return IsEmpty() ? -1 : (GetSpan().Inside(Frame) ? (IsStill() ? 0 : Frame - m_SourceOffset) : -1); }
private:
	FootageSPtr		m_pFootage;
	CXComp &		m_Comp;
	int				m_SourceOffset;
	Span			m_Trimming;
};

//#include "Background.inl"
